#!/bin/bash
HOME_PATH=${HOME}
function install(){
	software=$1
	locate=`which ${software}`
	if [ -z ${locate} ];then
		echo "${software} not exists and it will be install!"
		sudo apt install ${software} -y
	fi
}
function exist_repo(){
	repo=$1
	if [ ! -d ${HOME_PATH}/${repo} ];then
		cd ${HOME_PATH}
		git clone https://gitee.com/bleedingfight/${repo}.git 
	fi
}
function install_deb(){
    url=${1}
	package_name=`basename ${url}`
	wget ${url} -O /tmp/${package_name}
	sudo dpkg -i /tmp/${package_name}
}
vscode=`which code`
if [ -z ${vscode} ];then
    echo "===> install vscode"
    install_deb https://az764295.vo.msecnd.net/stable/d2e414d9e4239a252d1ab117bd7067f125afd80a/code_1.50.1-1602600906_amd64.deb
fi

install git
install vim
install tmux
exist_repo linux
zsh_config=${HOME_PATH}/linux/config/zsh-config
vim_config=${HOME_PATH}/linux/config/vim-config
tmux_config=${HOME_PATH}/linux/config/tmux-config


if [  -d ${zsh_config} ];then
    if [ ! -d ${HOME_PATH}/.oh-my-zsh ];then
        cd ${zsh_config}
        bash install.sh
		git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
		sed -i 's/plugins=(git)/plugins=(git zsh-syntax-highlighting)/g' ~/.zshrc


	else
		echo "===> zsh had configured"
	fi
fi

if [ -d ${vim_config} ];then
    echo "===> config vim ..."
    cd ${vim_config}
	if [ ! -f ${HOME_PATH}/.vim/autoload/plug.vim ];then
		mkdir -p ${HOME_PATH}/.vim/autoload
		cp plug.vim ${HOME_PATH}/.vim/autoload
        cp .vimrc ${HOME_PATH}
	else
		echo "===> vim had configured"
	fi
fi

if [ -d ${tmux_config} ];then
    cd ${tmux_config}
	if [ ! -f ${HOME_PATH}/.tmux.conf ];then
        cp -r .tmux.conf ${HOME_PATH}
	else
		echo "===> tmux had configured"
	fi
fi
